
#include "ChoiseFolderDialog.h"
#include "ui_ChoiseFolderDialog.h"
#include <QtWidgets/qfiledialog.h>

ChoiseFolderDialog::ChoiseFolderDialog(QWidget *parent) :
    QDialog(parent), ui(new Ui::ChoiseFolderDialog), m_nativeFolder(true)
{
    ui->setupUi(this);
    ui->toolButton->setIcon( style()->standardIcon(QStyle::SP_FileDialogNewFolder) );
    ui->lineEditName->setFocus();
}

ChoiseFolderDialog::~ChoiseFolderDialog()
{
    delete ui;
}

QString ChoiseFolderDialog::getFolderPath() const{
    return ui->lineEditFolder->text();
}
void ChoiseFolderDialog::setFolderPath(const QString& s){
    ui->lineEditFolder->setText(s);
}

QString ChoiseFolderDialog::getFilterName() const{
    return ui->lineEditName->text();
}
void ChoiseFolderDialog::setFilterName(const QString& s){
    ui->lineEditName->setText(s);
}

void ChoiseFolderDialog::setNativeFolder(const bool& b){
    m_nativeFolder = b;
}

void ChoiseFolderDialog::on_toolButton_clicked(){
    QFileDialog::Options option = QFileDialog::ShowDirsOnly;
    if(!m_nativeFolder){
        option |= QFileDialog::DontUseNativeDialog;
    }
    QString folder = QFileDialog::getExistingDirectory(this, trUtf8("Sélectionnez un Dossier"), getFolderPath(), option );
    if(folder.isEmpty())
        return;
    setFolderPath(folder);
}
